package com.zyx.springmvcmsb.advanced.handler;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author zyx
 * @since 2021/10/6 16:59
 */
@ControllerAdvice
public class MyGlobalExceptionHandler {

    @ExceptionHandler(value = {ArithmeticException.class, NullPointerException.class})
    public ModelAndView handlerException(Exception exception) {
        System.out.println("exception3");
        ModelAndView mv = new ModelAndView();
        mv.setViewName("error");
        mv.addObject("ex", exception);
        return mv;
    }

    @ExceptionHandler(value = {Exception.class})
    public ModelAndView handlerException2(Exception exception) {
        System.out.println("exception4");
        ModelAndView mv = new ModelAndView();
        mv.setViewName("error");
        mv.addObject("ex", exception);
        return mv;
    }
}
